package com.sumainfor.pc.epc.controller.direttore;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.epc.service.SettlementAuditService;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-04-09 18:30
 * 工程经理审核结算单打款
 */
@RestController
@RequestMapping("/audit/settlement")
public class SettlementAuditController {

    @Autowired
    private SettlementAuditService auditService;

    @PostMapping("/auditSettlement")
    public JsonResult auditSettlement(@RequestParam Map<String, Object> params) {
        String[] keys = {"StaRemId", "State"};
        if (!FieldCheckUtil.isMapFieldNotNull(params, keys)) {
            return JsonResult.errorForEmpty();
        }
        if (MapUtils.getInteger(params, "State").equals(2)) {
            if (StringUtils.isBlank(MapUtils.getString(params, "AuditNotes"))) {
                return JsonResult.error("驳回原因请填写");
            }
        }
        //添加数据
        return auditService.auditSettlement(params);
    }


}
